package com.software.car.config;

/**
 * @Author 魔法はまだ解けない
 * @Date 2021/1/29
 */

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 微信配置文件
 *
 * @Author 魔法はまだ解けない
 * @Date 2021/1/29
 */
@Component
public class WxMaConfiguration {
    /**
     * todo 这里注意，如果要配置，那么在application写上小程序的appid等信息即可
     */

    private static String appid;
    @Value("${classrepair.wx.appsecret}")
    private String appsecret;

    @Value("${classrepair.wx.appid}")
    public void setAppid(String appid) {
        WxMaConfiguration.appid = appid;
    }

    private static WxMaService wxMaService = null;

    @Bean
    public Object services(){
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(appid);
        config.setSecret(appsecret);

        wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);

        return Boolean.TRUE;
    }

    public static WxMaService getWxMaService(){
        return wxMaService;
    }

    public static String getAppid() {
        return appid;
    }
}
